package com.sgb.jicai.entity;

import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
import com.swgk.core.util.TimeUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 参与报价页面
 * 进入报价页面获取数据实体类
 */
public class OfferGroupBuyingDetailsEntity implements Serializable {

    @SerializedName("cityNo")
    private String cityNo;

    @SerializedName("detailsAddress")
    private String detailsAddress;

    @SerializedName("groupbuyingNo")
    private String groupbuyingNo;

    @SerializedName("districtName")
    private String districtName;

    @SerializedName("director")
    private String director;

    @SerializedName("directorNumber")
    private String directorNumber;
    private int groupBuyClass;

    @SerializedName("cityName")
    private String cityName;

    @SerializedName("offerNotes")
    private String offerNotes;

    @SerializedName("districtNo")
    private String districtNo;

    @SerializedName("provinceNo")
    private String provinceNo;

    @SerializedName("contactNumber")
    private String contactNumber;

    @SerializedName("provinceName")
    private String provinceName;

    @SerializedName("groupBuyType")
    private String groupBuyType;

    @SerializedName("contacts")
    private String contacts;

    @SerializedName("groupBuyingDetails")
    private List<GroupBuyingDetails> groupBuyingDetails;

    @SerializedName("records")
    private List<GroupBuyingDetails> records;

    @SerializedName("customerServiceContactsId")
    private String customerServiceContactsId;

    //限定截止时间---
    @SerializedName("deadline")
    private String deadline;

    //附件功能---
    @SerializedName("file")
    private String file;

    public int getGroupBuyClass() {
        return groupBuyClass;
    }

    public void setGroupBuyClass(int groupBuyClass) {
        this.groupBuyClass = groupBuyClass;
    }

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public String getGroupBuyType() {
        return groupBuyType;
    }

    public void setGroupBuyType(String groupBuyType) {
        this.groupBuyType = groupBuyType;
    }

    public String getDeadline() {
        return deadline;
    }

    public void setDeadline(String deadline) {
        this.deadline = deadline;
    }

    public String getCityNo() {
        return cityNo;
    }

    public void setCityNo(String cityNo) {
        this.cityNo = cityNo;
    }

    public String getDetailsAddress() {
        return detailsAddress;
    }

    public void setDetailsAddress(String detailsAddress) {
        this.detailsAddress = detailsAddress;
    }

    public String getGroupbuyingNo() {
        return groupbuyingNo;
    }

    public void setGroupbuyingNo(String groupbuyingNo) {
        this.groupbuyingNo = groupbuyingNo;
    }

    public String getDistrictName() {
        return districtName;
    }

    public void setDistrictName(String districtName) {
        this.districtName = districtName;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    public String getDirectorNumber() {
        return directorNumber;
    }

    public void setDirectorNumber(String directorNumber) {
        this.directorNumber = directorNumber;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public String getOfferNotes() {
        return offerNotes;
    }

    public void setOfferNotes(String offerNotes) {
        this.offerNotes = offerNotes;
    }

    public String getDistrictNo() {
        return districtNo;
    }

    public void setDistrictNo(String districtNo) {
        this.districtNo = districtNo;
    }

    public String getProvinceNo() {
        return provinceNo;
    }

    public void setProvinceNo(String provinceNo) {
        this.provinceNo = provinceNo;
    }

    public String getContactNumber() {
        return contactNumber;
    }

    public void setContactNumber(String contactNumber) {
        this.contactNumber = contactNumber;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public String getContacts() {
        return contacts;
    }

    public void setContacts(String contacts) {
        this.contacts = contacts;
    }

    public List<GroupBuyingDetails> getGroupBuyingDetails() {
        return groupBuyingDetails;
    }

    public void setGroupBuyingDetails(List<GroupBuyingDetails> groupBuyingDetails) {
        this.groupBuyingDetails = groupBuyingDetails;
    }

    public List<GroupBuyingDetails> getRecords() {
        return records;
    }

    public void setRecords(List<GroupBuyingDetails> records) {
        this.records = records;
    }

    public String getCustomerServiceContactsId() {
        return customerServiceContactsId;
    }

    public void setCustomerServiceContactsId(String customerServiceContactsId) {
        this.customerServiceContactsId = customerServiceContactsId;
    }

    public static class AttrsBean {
        private String name;
        private String value;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    public static class GroupBuyingDetails {
        //根据SupplyTime字段是否有值去控制删除按钮是否显示
        private int type = 1;

        @SerializedName("goodsDescribe")
        private String goodsDescribe;

        @SerializedName("no")
        private String no;

        @SerializedName("unitName")
        private String unitName;

        @SerializedName("groupbuyingDetailNo")
        private String groupbuyingDetailNo;

        @SerializedName("joinNum")
        private String joinNum;

        @SerializedName("rangeBrands")
        private String rangeBrands;

        @SerializedName("goodsName")
        private String goodsName;

        @SerializedName("attrs")
        private List<AttrsBean> attrs;

        /*   @SerializedName("attrlist")
           private List<AttrsBean> attrlist;*/
        @SerializedName("priceRule")
        private List<GroupBuyingDetails> priceRule;

        @SerializedName("details")
        private List<GroupBuyingDetails> details;

        /**
         * 区间起始值
         */
        private String intervalStartValue;
        /**
         * 区间结束值
         */
        private String intervalEndValue;
        /**
         * 价格
         */
        private String price;
        /**
         * 供货量
         */
        private String stock;
        /**
         * 市场最低价格
         */
        private String marketLowPrice;
        /**
         * 商品材料
         */
        private String goodsMaterial;
        /**
         * 质量标准
         */
        private String goodsQuality;
        /**
         * 维修保养
         */
        private String goodsMaintenance;
        /**
         * 商品用途
         */
        private String goodsPurpose;

        /**
         * 排序
         */
        private String sort;
        private int shoptype;

        public int getShoptype() {
            return shoptype;
        }

        public void setShoptype(int shoptype) {
            this.shoptype = shoptype;
        }

        public String getGoodsMaterial() {
            if (!TextUtils.isEmpty(goodsMaterial)) {
                return goodsMaterial;
            } else {
                return "/";
            }
        }

        public void setGoodsMaterial(String goodsMaterial) {
            this.goodsMaterial = goodsMaterial;
        }

        public String getGoodsQuality() {
            if (!TextUtils.isEmpty(goodsQuality)) {
                return goodsQuality;
            } else {
                return "/";
            }
        }

        public void setGoodsQuality(String goodsQuality) {
            this.goodsQuality = goodsQuality;
        }

        public String getGoodsMaintenance() {
            if (!TextUtils.isEmpty(goodsMaintenance)) {
                return goodsMaintenance;
            } else {
                return "/";
            }
        }

        public void setGoodsMaintenance(String goodsMaintenance) {
            this.goodsMaintenance = goodsMaintenance;
        }

        public String getGoodsPurpose() {
            if (!TextUtils.isEmpty(goodsPurpose)) {
                return goodsPurpose;
            } else {
                return "/";
            }
        }

        public void setGoodsPurpose(String goodsPurpose) {
            this.goodsPurpose = goodsPurpose;
        }

        /**
         * 供货结束时间
         */
        @SerializedName("supplyTime")
        private String supplyTime;

        /**
         * 供货开始时间
         */
        @SerializedName("supplyTimeStart")
        private String supplyTimeStart;

        //手动组装显示的数据
        private String priceRuleString;

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public List<GroupBuyingDetails> getDetails() {
            if (details == null) {
                details = new ArrayList<>();
            }
            if (details.size() == 0) {
                details.add(new GroupBuyingDetails());
            }
            return details;
        }

        public List<AttrsBean> getAttrs() {
            return attrs;
        }

        public void setAttrs(List<AttrsBean> attrs) {
            this.attrs = attrs;
        }

        public void setDetails(List<GroupBuyingDetails> details) {
            this.details = details;
        }

        public String getGoodsDescribe() {
            return goodsDescribe;
        }

        public void setGoodsDescribe(String goodsDescribe) {
            this.goodsDescribe = goodsDescribe;
        }

        public String getNo() {
            return no;
        }

        public void setNo(String no) {
            this.no = no;
        }

        public String getSupplyTime() {
            if (null != supplyTime && supplyTime.length() > 0 && !supplyTime.equals("0")) {
                try {
                    return TimeUtil.getDateStringYMD(Long.valueOf(supplyTime));
                } catch (Exception e) {
                    if (supplyTime.contains("-")) {
                        try {
                            supplyTime = String.valueOf(TimeUtil.getLongTime(supplyTime, "yyyy-MM-dd"));
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                    return TimeUtil.getDateStringYMD(Long.valueOf(supplyTime));
                }

            } else {
                return "";
            }
        }

        public void setSupplyTime(String supplyTime) {
            this.supplyTime = supplyTime;
        }

        public String getSupplyTimeStart() {
            if (null != supplyTimeStart && supplyTimeStart.length() > 0 && !supplyTimeStart.equals("0")) {
                try {
                    return TimeUtil.getDateStringYMD(Long.valueOf(supplyTimeStart));
                } catch (Exception e) {
                    if (supplyTimeStart.contains("-")) {
                        try {
                            supplyTimeStart = String.valueOf(TimeUtil.getLongTime(supplyTimeStart, "yyyy-MM-dd"));
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                    return TimeUtil.getDateStringYMD(Long.valueOf(supplyTimeStart));
                }

            } else {
                if (!TextUtils.isEmpty(supplyTime)) {
                    return TimeUtil.getDateStringYMD(Long.valueOf(Long.parseLong(supplyTime) - (24 * 60 * 60 * 1000)));
                } else {
                    return "";
                }
            }
        }

        public void setSupplyTimeStart(String supplyTimeStart) {
            this.supplyTimeStart = supplyTimeStart;
        }

        public String getStock() {
            return stock;
        }

        public void setStock(String stock) {
            this.stock = stock;
        }

        public String getMarketLowPrice() {
            return marketLowPrice;
        }

        public void setMarketLowPrice(String marketLowPrice) {
            this.marketLowPrice = marketLowPrice;
        }

        public String getSort() {
            if (TextUtils.isEmpty(sort)) {
                return "1";
            } else {
                return String.valueOf(Integer.valueOf(sort) + 1);
            }
        }

        public void setSort(String sort) {
            this.sort = sort;
        }

        public String getIntervalStartValue() {
            if (TextUtils.isEmpty(intervalStartValue)) {
                return "";
            }
            return intervalStartValue;
        }

        public void setIntervalStartValue(String intervalStartValue) {
            this.intervalStartValue = intervalStartValue;
        }

        public String getIntervalEndValue() {
            return intervalEndValue;
        }

        public void setIntervalEndValue(String intervalEndValue) {
            this.intervalEndValue = intervalEndValue;
        }

        public String getPrice() {
            if (TextUtils.isEmpty(price)) {
                price = "";
            }
            return price;
        }

        public void setPrice(String price) {
            this.price = price;
        }

        @Override
        public String toString() {
            String str = "";
            if (null == intervalEndValue || intervalEndValue.isEmpty()) {
                str = intervalStartValue + "吨以上 " + "  " + price + "元/吨";
            } else {
                str = intervalStartValue + " ~ " + intervalEndValue + "吨 " + "  " + price + "元/吨" + "\t";
            }
            return str;
//            return "PriceRule{" +"sort='" + sort + '\'' +
//                    ", intervalStartValue='" + intervalStartValue + '\'' +
//                    ", intervalEndValue='" + intervalEndValue + '\'' +
//                    ", price='" + price + '\'' +
//                    '}';
        }

        public String getUnitName() {
            return unitName;
        }

        public void setUnitName(String unitName) {
            this.unitName = unitName;
        }

        public String getGroupbuyingDetailNo() {
            return groupbuyingDetailNo;
        }

        public void setGroupbuyingDetailNo(String groupbuyingDetailNo) {
            this.groupbuyingDetailNo = groupbuyingDetailNo;
        }

        public String getJoinNum() {
            return joinNum;
        }

        public void setJoinNum(String joinNum) {
            this.joinNum = joinNum;
        }

        public String getRangeBrands() {
            return rangeBrands;
        }

        public void setRangeBrands(String rangeBrands) {
            this.rangeBrands = rangeBrands;
        }

        public String getGoodsName() {
            return goodsName;
        }

        public void setGoodsName(String goodsName) {
            this.goodsName = goodsName;
        }

        public List<GroupBuyingDetails> getPriceRule() {
            return priceRule;
        }

        public void setPriceRule(List<GroupBuyingDetails> priceRule) {
            this.priceRule = priceRule;
        }

        public String getPriceRuleString() {
            if (null != priceRule && priceRule.size() > 0) {
                StringBuffer str = new StringBuffer();
                for (int i = 0; i < priceRule.size(); i++) {
                    GroupBuyingDetails rule = priceRule.get(i);
                    if (null == rule.intervalEndValue || rule.intervalEndValue.isEmpty()) {
                        if (i == getPriceRule().size() - 1) {
                            str.append(rule.intervalStartValue + getUnitName() + "以上  " + rule.price + "元/" + getUnitName());
                        } else {
                            str.append(rule.intervalStartValue + getUnitName() + "以上  " + rule.price + "元/" + getUnitName() + "\n");
                        }
                    } else {
                        if (i == getPriceRule().size() - 1) {
                            str.append(rule.intervalStartValue + " ~ " + rule.intervalEndValue + " " + getUnitName() + "  " + rule.price + "元/" + getUnitName());
                        } else {
                            str.append(rule.intervalStartValue + " ~ " + rule.intervalEndValue + " " + getUnitName() + "  " + rule.price + "元/" + getUnitName() + "\n");
                        }
                    }
                }
                return String.valueOf(str).contains("null") ? "" : String.valueOf(str);
            } else {
                return "";
            }
        }

        public void setPriceRuleString(String priceRuleString) {
            this.priceRuleString = priceRuleString;
        }
    }

    @Override
    public String toString() {
        return "OfferGroupBuyingDetailsEntity{" +
                "cityNo='" + cityNo + '\'' +
                ", detailsAddress='" + detailsAddress + '\'' +
                ", groupbuyingNo='" + groupbuyingNo + '\'' +
                ", districtName='" + districtName + '\'' +
                ", director='" + director + '\'' +
                ", directorNumber='" + directorNumber + '\'' +
                ", cityName='" + cityName + '\'' +
                ", offerNotes='" + offerNotes + '\'' +
                ", districtNo='" + districtNo + '\'' +
                ", provinceNo='" + provinceNo + '\'' +
                ", contactNumber='" + contactNumber + '\'' +
                ", provinceName='" + provinceName + '\'' +
                ", groupBuyType='" + groupBuyType + '\'' +
                ", contacts='" + contacts + '\'' +
                ", groupBuyingDetails=" + groupBuyingDetails +
                ", records=" + records +
                ", customerServiceContactsId='" + customerServiceContactsId + '\'' +
                ", deadline='" + deadline + '\'' +
                ", file='" + file + '\'' +
                '}';
    }

    public static class FilesBean {
        private String name;
        private String url;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }
    }
}
